from views import page as pageBase

from api import api


class ProductTemplate(object):
    page = pageBase.productTemplate

    def test(self,):
        pass
        # self.test_onchange2()
        # self.test_search()
        # self.test_create()

        # self.test_write()

    def test_onchange2(self,):
        field_onchange = {
            # "name": "",
            # "type": "1",
            # "uom_id": "1",
            # "uom_po_id": "1",
            # "categ_id": "1",
            # "company_id": "1",

            # "cost_currency_id": "",
            # "currency_id": "",
            # "default_code": "",
            # "list_price": "",
            # "name": "",
            # "purchase_ok": "",
            # "sale_ok": "",
            # "standard_price": "",
            # "supplier_taxes_id": "",
            # "taxes_id": "",



            "product_variant_count": "",
            "is_product_variant": "",
            "attribute_line_ids": "",
            "attribute_line_ids.attribute_id": "1",
            "attribute_line_ids.value_ids": "",
            "id": "",
            "image_1920": "",
            "__last_update": "",
            "name": "",
            "sale_ok": "",
            "purchase_ok": "",
            "active": "",
            "type": "1",
            "categ_id": "1",
            "default_code": "",
            "barcode": "",
            "list_price": "",
            "pricelist_item_count": "",
            "taxes_id": "",
            "standard_price": "",
            "uom_name": "",
            "company_id": "1",
            "uom_id": "1",
            "uom_po_id": "1",
            "currency_id": "",
            "cost_currency_id": "",
            "product_variant_id": "",
            "description": "",
            "description_sale": "",
            "supplier_taxes_id": "",
            "weight": "",
            "weight_uom_name": "",
            "volume": "",
            "volume_uom_name": "",
            "property_account_income_id": "",
            "property_account_expense_id": "",
            "asset_category_id": "",

            # "packaging_ids": "",
            # "packaging_ids.name": "",
            # "packaging_ids.qty": "",
            # "packaging_ids.product_uom_id": "",
            # "packaging_ids.company_id": "",
            # "message_follower_ids": "",
            # "message_follower_ids.res_model": "",
            # "message_follower_ids.res_id": "",
            # "message_follower_ids.partner_id": "",
            # "message_follower_ids.channel_id": "",
            # "activity_ids": "",
            # "activity_ids.res_name": "",
            # "activity_ids.activity_type_id": "1",
            # "activity_ids.summary": "",
            # "activity_ids.date_deadline": "",
            # "message_ids": "",
            # "message_ids.date": "",
            # "message_ids.subject": "",
            # "message_ids.author_id": "",
            # "message_ids.model": "",
            # "message_ids.res_id": ""
        }
        res = api.odooenv['product.template'].onchange2(
            [], {}, [], field_onchange)

        print('--value-')
        for r, v in res['value'].items():
            print(r, v)
        print('--domain-')
        for r, v in res['domain'].items():
            print(r, v)
        print('--fields-')
        for r, v in res['fields'].items():
            print(r, v)

    def test_search(self):
        self.page.search([])

        print('sech ok,', self.page.store.dataList)

    def test_search(self):
        print('1, _store', self.vuexStore)
        self.handleSearch()
        print('2, _store', self.vuexStore)
        print('2, vuexStore.dataList', self.vuexStore['dataList'])

    def test_create(self):
        print('1', self.vuexStore)
        self.handleNew()
        print('2', self.vuexStore['dataDict'])
        print('3', self.vuexStore['formData'])
        print('3', self.vuexStore['domain'])

        # # 编辑
        # # onchange
        # values = {'type': 'service'}
        # record = self.handleOnchange(record,  values)
        # print('2', record)

        # values = {'name': 'www33'}
        # record = self.handleOnchange(record,  values)

        # # print(record)

        # # create
        # res = self.create2(record, fields=['currency_id'], context=context)
        # print(res)

    def test_write(self):
        # 读数
        record = self.search_one([('name', '=', 'www33')])
        rid = record['id']
        record = self.handleEdit(rid)

        # 编辑
        values = {'type': 'consu'}

        # onchange
        record = self.handleOnchange(record,  values)
        print(record)

        # write
        context = self.metadata['context']
        res = self.write2(rid, values, context=context)
        print(res)


productTemplate = ProductTemplate()
